package com.apobates.forum.toro.template;

import com.apobates.forum.toro.core.TypeEnum;

/**
 * 模板聚合语句表达式
 * 适用于: 值对象模板模式
 *
 * @author xiaofanku@live.cn
 * @since 20220517
 */
public class TemplateExpression {
    private final String targetAttr;
    private final String selectAttr;
    private final String selectAttrTypeName;

    private TemplateExpression(Builder builder) {
        this.targetAttr = builder.targetAttr;
        this.selectAttr = builder.selectAttr;
        this.selectAttrTypeName = builder.selectAttrTypeName;
    }

    public String getTargetAttr() {
        return targetAttr;
    }

    public String getSelectAttr() {
        return selectAttr;
    }

    public String getSelectAttrTypeName() {
        return selectAttrTypeName;
    }

    public static class Builder{
        private String targetAttr;
        private String selectAttr;
        private String selectAttrTypeName;

        public static Builder newInstance() {
            return new Builder();
        }

        private Builder() {}

        public Builder target(String targetAttr) {
            this.targetAttr = targetAttr;
            return this;
        }

        /**
         *
         * @param selectAttr
         * @return
         */
        public Builder used(String selectAttr) {
            this.selectAttr = selectAttr;
            return this;
        }

        /**
         *
         * @param selectAttrTypeName
         * @return
         */
        public Builder usedType(String selectAttrTypeName) {
            this.selectAttrTypeName = selectAttrTypeName;
            return this;
        }

        /**
         *
         * @param selectAttrType
         * @return
         */
        public Builder usedType(TypeEnum selectAttrType) {
            this.selectAttrTypeName = selectAttrType.getType();
            return this;
        }

        /**
         *
         * @return
         */
        public TemplateExpression build(){
            return new TemplateExpression(this);
        }
    }
}
